// 引入路由
import Home from '../pages/Home'
import Register from '../pages/Register'
import Login from '../pages/Login'
import Search from '../pages/Search'
import Detail from '../pages/Detail'
import AddCartSuccess from '../pages/AddCartSuccess'
import ShopCart from '../pages/ShopCart'
import Trade from '../pages/Trade'
import Pay from '../pages/Pay'
import PaySuccess from '../pages/PaySuccess'
import Center from '../pages/Center'
// 引入二级路由组件
import MyOrder from '../pages/Center/myOrder'
import GroupOrder from '../pages/Center/groupOrder'


export default [
  // 从定向
  {
    path: '/center',
    component: Center,
    meta: { show: true },
    children: [
      {
        path: 'myorder',
        component: MyOrder,
      },
      {
        path: 'grouporder',
        component: GroupOrder,
      },
      {
        path: '/center',
        redirect: '/center/myorder',
      },
    ],
  },
  { path: '/paysuccess', component: PaySuccess, meta: { show: true } },
  {
    path: '/pay',
    component: Pay,
    meta: { show: true },
    // 路由独享守卫
    beforeEnter: (to, from, next) => {
      if (from.path == '/trade') {
        next()
      } else {
        next(false)
      }
    },
  },
  { path: '*', redirect: '/home' },
  { path: '/home', component: () =>import("@/pages/Home"), meta: { show: true } },
  { path: '/register', component: Register, meta: { show: false } },
  { path: '/login', component: Login, meta: { show: false } },
  {
    path: '/addcartsuccess',
    name: 'addcartsuccess',
    component: AddCartSuccess,
    meta: { show: false },
  },
  { path: '/shopcart', component: ShopCart, meta: { show: false } },
  {
    path: '/search/:keyword?',
    component: ()=>import("@/pages/Search"),
    meta: { show: true },
    name: 'search',
    // 布尔值写法，params
    // props:true
    // 对象写法
    // props:{a:1,b:2}
    // 函数写法
    props: ($route) => {
      return {
        keyword: $route.params.keyword,
        k: $route.query.k,
      }
    },
  },
  { path: '/detail/:skuid', component: Detail, meta: { show: false } },
  {
    path: '/trade',
    component: Trade,
    meta: { show: true },
    // 路由独享守卫
    beforeEnter: (to, from, next) => {
      if (from.path == '/shopcart') {
        next()
      } else {
        next(false)
      }
    },
  },
]
